﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "WallTagManipulateStrategy.h"
#include "ElementUiManipulateStrategyRegister.h"
#include "IElementPositionPoints.h"
#include "IElementShapeHandleBehavior.h"
#include "IElementShapeHandle.h"
#include "IElementBasicInformation.h"
#include "WallTag.h"
#include "WallTagShapeHandleBehavior.h"
#include "IModelView.h"
#include "IGraphicsElementShape.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace Sample;
using namespace gcmp;

//夹点管理类与对象实现类需要进行关联
REGISTER_ELEMENT_UIMANIPULATE_STRATEGY(WallTag, WallTagManipulateStrategy);

std::vector<gcmp::ElementId> WallTagManipulateStrategy::CreateAuxiliaryElements(gcmp::IModelView* pModelView, const IElement* pElement) const
{
    //生成夹点
    std::vector<gcmp::ElementId> elementIds;
    DBG_WARN_AND_RETURN_UNLESS(pElement, elementIds, L"Element不能为空",L"GDMP",L"2023-12-30");
    const IElementPositionPoints* pPositionPoints = pElement->GetPositionPoints();
    DBG_WARN_AND_RETURN_UNLESS(pPositionPoints, elementIds, L"Element定位信息不能为空",L"GDMP",L"2023-12-30");
    IElementBasicInformation* pElementBasicInformation = pModelView->GetBasicInformation();
    DBG_WARN_AND_RETURN_UNLESS(pElementBasicInformation, elementIds, L"ElementBasicInformation获取失败",L"GDMP",L"2023-12-30");
    for (int index = 0; index < pPositionPoints->GetControlPointCount(); ++index)
    {
        OwnerPtr<IElementShapeHandleBehavior> opShapeHandleBehavior =
            NEW_AS_OWNER_PTR(WallTagShapeHandleBehavior, pElement->GetDocument(), pElementBasicInformation->GetElementId());

        Vector3d pt = pPositionPoints->GetControlPoint(index);
        IElementShapeHandle* pElementShapeHandle =
            IElementShapeHandle::Create(TransferOwnership(opShapeHandleBehavior), pElement->GetElementId(), pt, index);
        DBG_WARN_AND_RETURN_UNLESS(pElementShapeHandle, elementIds, L"ElementShapeHandle创建失败",L"GDMP",L"2023-12-30");
        IElementBasicInformation* pElementBasicInformation1 = pElementShapeHandle->GetBasicInformation();
        DBG_WARN_AND_RETURN_UNLESS(pElementBasicInformation1, elementIds, L"ElementBasicInformation获取失败",L"GDMP",L"2023-12-30");
        elementIds.push_back(pElementBasicInformation1->GetElementId());
    }
    return elementIds;
}